package com.zoshine.zzg.controller;

import com.github.pagehelper.PageInfo;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.pojo.Account;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 账户Controller
 * @author 田沛凌
 * @time 2017年7月7日 下午7:25:20
 */
@RestController
@RequestMapping(value = "/account",method = RequestMethod.POST)
public class AccountController {
    private AccountService accountService;
    @Autowired
    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }
    /**
     * 新增账户
     * @param account
     * @return
     */
    @RequestMapping("/addAccount")
    public BaseResponse addAccount(Account account){
        accountService.add(account);
        return AppResponse.OK;
    }
    /**
     * 修改账户信息
     * @param account
     * @return
     */
    @RequestMapping("/editAccount")
    public BaseResponse editAccount(Account account){
        accountService.edit(account);
        return AppResponse.OK;
    }
    /**
     * 获取账户信息(单个账户)
     * @param id (账户ID)
     * @return
     */
    @RequestMapping("/getAccount")
    public BaseResponse getAccount(Long id){
        Account account = accountService.get(id);
        return new AppResponse(account);
    }
    /**
     * 账户集合查询
     * @param account
     * @return 账户集合
     */
    @RequestMapping("/pageAccount")
    public BaseResponse pageAccount(Account account){
        List<Account> listAccount = accountService.list(account);
        return new AppResponse(new PageInfo<>(listAccount));
    }
    
}
